﻿// See https://aka.ms/new-console-template for more information
using BeetleX.MQTT;
using BeetleX.MQTT.Messages;

public class Class1
{
    public static long mCount;

    public static long mLastCount;

    private static void Test(string topic, string id)
    {
        Task.Run(async () =>
        {
            MQTTClient<MQTTParse> client = new MQTTClient<MQTTParse>(id, "localhost", 8089);
            client.ClientInfo.SetUser("S", "123456");
            await client.Connect();
            await client.Sub(topic, QoSType.MostOnce);
            Console.WriteLine($"{DateTime.Now:HH:mm:ss}\t Test_RECA receive from [{topic}]...");
            while (true)
            {
                await client.Receive();
                System.Threading.Interlocked.Increment(ref mCount);
            }
        });
    }
    static void Main()
    {
        Test("/driver/A/#", "MQTT_A_SUB");
        Test("/driver/B/#", "MQTT_B_SUB");
        Test("/driver/C/#", "MQTT_C_SUB");
        Test("/driver/D/#", "MQTT_D_SUB");
        Test("/driver/E/#", "MQTT_E_SUB");
        Test("/driver/F/#", "MQTT_F_SUB");
        Test("/driver/+/1", "MQTT_*1_SUB");
        Test("/driver/+/2", "MQTT_*2_SUB");
        Test("/driver/+/3", "MQTT_*3_SUB");
        Test("/driver/+/4", "MQTT_*4_SUB");
        while (true)
        {
            Console.WriteLine($"{DateTime.Now:HH:mm:ss}\t {(mCount - mLastCount):###,###,##0}/秒[总接收量:{mCount:###,###,##0}]");
            mLastCount = mCount;
            System.Threading.Thread.Sleep(990);
        }

    }
}

